package com.example.personalcenter.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import com.example.personalcenter.databinding.FragmentHomeBinding;
import com.example.personalcenter.model.UserViewModel;

public class HomeFragment extends Fragment {

    private FragmentHomeBinding binding;
    private UserViewModel userVM;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        binding = FragmentHomeBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view,
                              @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        userVM = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
        userVM.getInterest().observe(getViewLifecycleOwner(), interest ->
                binding.tvTips.setText("根据您的兴趣【" + interest + "】，推荐内容如下"));
    }
}